import { Utils } from '../utils/utils';
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
    name: 'decimal'
})
export class DecimalPipe implements PipeTransform {

    transform(value: any, args?: any): any {
        if (Utils.isNumber(value)) {
            return Utils.decimal(value, args || 2).toFixed(args || 0);
        } else {
            const a = parseInt(value, 10);
            if (isNaN(a)) {
                return 0;
            } else {
                return Utils.decimal(value, args || 2).toFixed(args || 0);
            }
        }
    }

}
